package com.aloda.controller.user;

import com.aloda.dto.UserLoginDTO;
import com.aloda.dto.UserRegisterDTO;
import com.aloda.result.Result;
import com.aloda.service.UserService;
import com.aloda.vo.UserLoginVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user/page")
@Slf4j
public class PageController {

    @Autowired
    private UserService userService;


    /**
     * 用户端用户注册
     * @param userRegisterDTO
     * @return
     */
    @PostMapping("/register")
    public Result register(@RequestBody UserRegisterDTO userRegisterDTO){
        log.info("用户端用户注册：{}",userRegisterDTO);
        userService.register(userRegisterDTO);
        return Result.success();
    }

    /**
     * 用户端用户登录
     * @param userLoginDTO
     * @return
     */
    @PostMapping("/login")
    public Result<UserLoginVO> login(@RequestBody UserLoginDTO userLoginDTO){
        log.info("用户端用户登录：{}",userLoginDTO);
        UserLoginVO userLoginVO = userService.login(userLoginDTO);
        log.info("返回登录消息：{}",userLoginVO);
        return Result.success(userLoginVO);
    }
}
